<?php
defined('SEJUJOPEFDNGJSL') or exit('Access denied');
function get_njxx($uid,$n=10000000){
    global $db;
    $db->query("select id,uname,parents_ids,is_passed from ld_user_account",1);
    $users=$db->rs;
    $list=array();
    foreach($users as $v){
        $arr=par_arr($v['parents_ids']);
        $k=array_search($uid,$arr);
        if(($k===false)||($v['is_passed'])==0){
            continue;
        }
        $to=count($arr);
        if(($to-$k-1)<=($n-1)){
            $list[]=$v['id'];
        }
    }
    return $list;
}
function tdcal($uid){
	global $db;
	$sql="select count(0) as num from ld_user_account where parents_ids like '%,$uid,%' and is_freezed=0 and is_passed=1";
	$db->query($sql,2);
	$tdnum=$db->rs['num'];
	return intval($tdnum);
}
function ztcal($uid){
	global $db;
	$db->query("select count(0) as num from ld_user_account where is_freezed=0 and is_passed=1 and introducer_id = ".$uid,2);
	$ztnum=$db->rs['num'];
	return intval($ztnum);
}
if($_POST['submit']=='禁止用户'){
	if(empty($_POST["cbid"])) show_automsg('请先选择要禁止的用户！',$GLOBALARR['curl'],1);
	$u_id=implode(",",$_POST["cbid"]);
	try{
		$db->begintransaction();
		$db->lspre("update ld_user_account set is_freezed=1,freezed_time=:t1,freezed_reason='管理员禁止用户' where id=:t0",4,array(array(':t0',':t1'),array($u_id,time())));
		$user_give_help = $db->rs;
		$db->committransaction();
	}catch(PDOException $e){
		$db->rollbacktransaction();
		a_bck("error");
	}
	record_log('禁止用户');
	show_automsg('禁止用户成功！',$GLOBALARR['curl']);
} 
if($_POST['submit']=='解封用户'){
	if(empty($_POST["cbid"])) show_automsg('请先选择要解封的用户！',$GLOBALARR['curl'],1);
	$u_id=implode(",",$_POST["cbid"]);
	$member_info = $member->getuserinfo($u_id);
	if(1==1||$member_info['freezed_reason'] == '管理员禁止用户' || $member_info['freezed_reason'] == '48小时内大于等于5名下线被封号'){
		if($member_info['freezed_reason'] == '主动拒绝付款'){
			show_automsg('此用户主动拒绝付款，不能解封！',$GLOBALARR['curl'],1);
		}
		try{
			$db->begintransaction();
			$db->sitedbexec("update ld_user_account set is_freezed = 0  where id = ".$u_id);
			$db->committransaction();
		}catch(PDOException $e){
			$db->rollbacktransaction();
			a_bck("error");
		}
		record_log('解封用户');
		show_automsg('解封用户成功！',$GLOBALARR['curl']);
	}else{
		show_automsg('此用户的封号原因是：'.$member_info['freezed_reason'].'，不在可解封的范围内！',$GLOBALARR['curl'],1);
	}
}

$pagecount=getnums($_GET["pagecount"],$GLOBALARR['pagecount']);
$option=getnums($_GET['option'],2);
$orderby=getnums($_GET['orderby'],1);
$quser=trim($_GET['quser']);


$tmp_arr['toption'].='<input type="submit" name="submit" onclick="return boxcheck(\'请先选择要禁止的用户\',\'您确定要禁止用户吗?\',\'正在执行中,请耐心等待！\');"    value="禁止用户" class="thabtn">'
        . '<input type="submit" name="submit" onclick="checkone();"    value="解封用户" class="thabtn">'
        . '<a href="'.getqueurl('option',1).'" class="'.geteqval(array($option,1,'taselbtn','thabtn')).'">今日新增</a>'
        . '<a href="'.getqueurl('option',2).'" class="'.geteqval(array($option,2,'taselbtn','thabtn')).'">全部会员</a>';

$tmp_arr['torderby']='<a href="'.getqueurl('orderby',geteqval(array($orderby,1,'2','1'))).'" class="'.((strstr($orderby,'1')||strstr($orderby,'2'))?"tpaixusel":"tpaixu").'">'.geteqval(array($orderby,1,'时间↓','时间↑')).'</a>';

if(is_array($GLOBALARR['jjname'])){
	foreach ($GLOBALARR['jjname'] as $k => $v) {
		$tmp_arr['tcolor'].='<a href="'.getqueurl('lever',$k).'" class="theacolor levelcolor'.$k.'">'.$v.'</a>';
	}
}

$condition=' where is_passed = 1  ';

if($quser){
	if(strstr($quser,"=")){
		$qdate=explode('=',$quser);
		if($qdate[0]) $condition.=" and from_unixtime(regist_time,'%Y')=".$qdate[0]."";
		if($qdate[1]) $condition.=" and from_unixtime(regist_time,'%m')=".$qdate[1]."";
		if($qdate[2]) $condition.=" and from_unixtime(regist_time,'%d')=".$qdate[2]."";
	}else{
		$condition.=" and (ld_user_account.uname like '%".$quser."%' or phone='".$quser."')";
	}
} 
$start_time = strtotime(date("Y-m-d"));
$end_time = strtotime(date("Y-m-d")." 23:59:59"); 
if($option==1) $condition.=" and regist_time>=".$start_time." and regist_time<=".$end_time;
$levers=$_GET['lever'];
// var_dump($condition);
if( $levers>=0 && isset($_GET['lever']) ){
	$condition.= " and user_level=".$levers;
}

$order='';
if($orderby==1) $order=' order by regist_time desc';
if($orderby==2) $order=' order by regist_time asc';

$tmp_arr['tth']='<th></th><th>序号</th><th>会员账号</th><th>姓名</th><th>手机号</th><th>直推数</th><th>团队数</th><th>总金额</th><th>商品积分</th><th>利息</th><th>领导奖</th><th>晋级奖</th><th>积分</th><th>共享积分</th><th>排单累计</th><th>状态</th><th>激活时间</th><th>推荐人</th><th>修改资料</th>';

$psql="select count(0) from ld_user_account left join ld_user_info on ld_user_account.id=ld_user_info.id $condition";
// var_dump($psql);
$db->query($psql,3);
$pcount=$db->fval;
$pagecount=$pagecount;   //每页条数 
if($levers){
	$astr="&lsaction=formallist&pagecount=$pagecount&orderby=$orderby&option=$option&quser=$quser&lever=$levers";	
}else{
	$astr="&lsaction=formallist&pagecount=$pagecount&orderby=$orderby&option=$option&quser=$quser";	
}
$pagearr=pagelist($pagecount,$pcount,$astr);
$offset=$pagearr[1];
$sql="select * from ld_user_account left join ld_user_info on ld_user_account.id=ld_user_info.id   $condition $order limit $offset,$pagecount";
$db->query($sql);
$ii=0;
foreach ($db->rs as $k => $v) {
	if($_username!=='tianxiayhe'&&$v['id']==8501){
		// continue;
	}
	$ii++;
	$serialid=($pagearr[2]-1)*$pagecount+$ii;
	$rm=$member->getum($v['uname'],'id,real_name,user_jibie,nick_name');
	//用户状态
	if(($v['is_freezed']==0)&&($v['is_passed']==0)){
		$state='未激活';//未激活3
		$co='';
	}
	if(($v['is_freezed']==0)&&($v['is_passed']==1)&&($v['had_ghelp_mark']==0)){
		$state='已激活';//已激活1
		$co='blue';
	}
	if(($v['is_freezed']==0)&&($v['is_passed']==1)&&($v['had_ghelp_mark']==1)){
		$state='正常';//正常（已激活完成一次提供帮助且未被封）2
		$co='green';
	}
	if($v['is_freezed']==1){
		$state='封号';//封号4
		$co='red';
	}
	$jinji="";
	if($v['user_jjlever']==1){
		$jinji="(银)";
	}
	if($v['user_jjlever']==2){
		$jinji="(金)";
	}
	if($v['user_jjlever']==3){
		$jinji="(钻)";
	}
	$lever=$v['user_level'];
	$tot=$v['cash_purse']+$v['lixi_crash']+$v['cash_ldprize']+$v['rise_crash']+$v['fuxiao_crash'];
	$dongjie = ($v['is_freezed']==1)?'<span style="color:red">已禁止|</span>':'';
	$tmp_arr['ttr'].='<tr class="levelcolor'.$lever.'">
					<td><input type="radio" name="cbid[]" value="'.$v['id'].'"></td>
					<td><span  title="'.$v["id"].'">'.$serialid.'</span></td>
					<td>'.$v['uname'].'</td>
					<td>'.$rm['real_name'].$jinji.'</td>
					<td>'.$v['phone'].'</td>
					<td>'.ztcal($v['id']).'</td>
					<td>'.tdcal($v['id']).'</td>
					<td>'.$tot.'</td>
					<td>'.($v['cash_purse']).'</td>
					<td>'.$v['lixi_crash'].'</td>
					<td>'.$v['cash_ldprize'].'</td>
					<td>'.$v['rise_crash'].'</td>
					<td>'.$v['point_crash'].'</td>
					<td>'.$v['fuxiao_crash'].'</td>
					<td>'.$v['benifit_purse'].'</td>
					<td style="color:'.$co.'">'.$state.'</td>
					<td>'.date("Y-m-d",$v['open_time']).'</td>
					<td>'.getparentuser($v['introducer_id']).'</td>
					<td><a href="main.php?lsaction=moduserinfo&edid='.$rm['id'].'">修改信息</td>
					</tr>';
}
$tmp_arr['tcount']=$pcount;
$tmp_arr['ttitle']=getmenu($GLOBALARR['menu'],'formallist');

$tmp_arr['tpage']=$pagearr[0];
admin_two($tmp_arr);

?>